package edu.ccut.saturn.studio.wfg.dialog.humanactivitydialog;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolTip;


import edu.ccut.saturn.studio.Activator;
import edu.ccut.saturn.studio.Images;
import edu.ccut.saturn.studio.core.search.SaturnFileSearcher.SearchResult;
import edu.ccut.saturn.studio.core.search.dialog.TwoCompontentSearchDialog;
import edu.ccut.saturn.studio.core.util.eclipse.Messages;
import edu.ccut.saturn.studio.database.model.DBConnection;
import edu.ccut.saturn.studio.database.model.DBConnectionProvider;
import edu.ccut.saturn.studio.database.model.DBConnection.DBConnectionListener;
import edu.ccut.saturn.studio.wfg.dialog.ActivitySelectionDialog;
import edu.ccut.saturn.studio.wfg.dialog.CustomDefineParticipantDialog;
import edu.ccut.saturn.studio.wfg.dialog.RevertCandidate;
import edu.ccut.saturn.studio.wfg.dialog.SelectionCandidate;
import edu.ccut.saturn.studio.wfg.dialog.TableViewerContentProvider;
import edu.ccut.saturn.studio.wfg.dialog.formdatadialog.FormDataAttributeLabelProvider;
import edu.ccut.saturn.studio.wfg.dialog.formdatadialog.MyCellModifierFormDataAttribute;
import edu.ccut.saturn.studio.wfg.dialog.formdatadialog.SaturnFormDataDialogForAdd;
import edu.ccut.saturn.studio.wfg.dialog.formdatadialog.SaturnFormDataDialogForDoubleClick;
import edu.ccut.saturn.studio.wfg.dialog.formdatadialog.SaturnFormDataDialogForEdit;
import edu.ccut.saturn.studio.wfg.dialog.userdialog.MyCellModifierUsersAttribute;
import edu.ccut.saturn.studio.wfg.dialog.userdialog.UserAddNew;
import edu.ccut.saturn.studio.wfg.dialog.userdialog.UserEditNew;
import edu.ccut.saturn.studio.wfg.dialog.userdialog.UsersAttributeLabelProvider;
import edu.ccut.saturn.studio.wfg.dialog.vocationallogicdialog.LogicKeyAttributeLabelProvider;
import edu.ccut.saturn.studio.wfg.dialog.vocationallogicdialog.SaturnVocationalLogicDialogForAdd;
import edu.ccut.saturn.studio.wfg.dialog.vocationallogicdialog.SaturnVocationalLogicDialogForEdit;
import edu.ccut.saturn.studio.wfg.model.Shape;
import edu.ccut.saturn.studio.wfg.model.ShapesDiagram;
import edu.ccut.saturn.studio.wfg.wfgmodel.FormDataAttribute;
import edu.ccut.saturn.studio.wfg.wfgmodel.LogicKeyAttribute;
import edu.ccut.saturn.studio.wfg.wfgmodel.SaturnAttribute;
import edu.ccut.saturn.studio.wfg.wfgmodel.SaturnHumanNode;
import edu.ccut.saturn.studio.wfg.wfgmodel.SaturnMultiWork;
import edu.ccut.saturn.studio.wfg.wfgmodel.SaturnParticipator;
import edu.ccut.saturn.studio.wfg.wfgmodel.SaturnStartNode;
import edu.ccut.saturn.studio.wfg.wfgmodel.UsersAttribute;

public class SaturnHumanActivityDialog extends TitleAreaDialog {

	SaturnHumanNode saturnHumanNode = new SaturnHumanNode();

	private List<Shape> shapes = new ArrayList<Shape>();

	private CellEditor[] cellEditor;
	
	// 基本信息
	private Label activityIdLabel, activityNameLabel, timeLimitLabel,
			polymeModeLabel, descriptionLabel;
	
	private Text activityIdText, activityNameText, timeLimitText, descriptionText;
	
	private Combo polymeModeCombo;
	
	private LogicKeyAttribute logicKeyAttribute;

	private List<SaturnAttribute> logicKeyTemp;
	
	private TableViewer tableViewer;
	
	private Text afterRequireText;
	
	private Label imageLabel;
	
	private Table table;
	
	private Button insertButton, deleteButton, upbutton, downbutton, editButton;
	
	// formData表单信息
	private List<SaturnAttribute> formDataTemp;
	
	private Label URLLabel; // URLText为自定义表单
	
	private Text URLText; // URLText为自定义表单
	
	private TableViewer tableViewer_2;

	private Table table_2;
	
	private Button insertButton_2, deleteButton_2, upbutton_2, downbutton_2,editButton_2;
	
	// user表单信息
	private SaturnParticipator saturnParticipator;
	
	private UsersAttribute usersAttribute;
	
	private List<SaturnAttribute> userTemp;
	
	private TableViewer tableViewer_3;
	
	private DBConnection dbConnection = null;
	
	private String connectname = "";
	
	private Table table_3;
	
	private String idWrite = "";
	
	private String idRead = "";
	
	private Label validateUserLogicLabel, obtainFromActivityLabel;
	
	private Text validateUserLogicText, obtainFromActivityText, customDefineParticipantText;
	
	private Button organizationAndRoleButton, flowStartuperButton,
			flowExecutorButton, obtainFromActivityButton, customDefineParticipantButton,
			customDefineParticipantButton2, insertButton_3,	deleteButton_3, upbutton_3, 
			downbutton_3, editButton_3;

	// 多工作项的东西
	private SaturnMultiWork saturnMultiWork;
	
	private Group group_4;

	private Button multiWorkButton, finishAllButton, finishNumberButton, finishPercentButton;

	private Combo isAutoCancelCombo;

	private Text finishRequiredNumText, finishRequiredPercentText;

	private Label finishRequiredNumLabel, finishRequiredPercentLabel, sympolLabel, isAutoCancelLabel;
	
	public SaturnHumanActivityDialog(Shell parentShell, SaturnHumanNode saturnHumanNode) {
		super(parentShell);
		this.saturnHumanNode = saturnHumanNode;
		this.copyLogicKeyList(saturnHumanNode.getLogicKeyList());
		this.copyFormDataList(saturnHumanNode.getFormDataAttributeList());
		this.saturnParticipator = this.saturnHumanNode.getSaturnParticipator();
		this.copyUsersList(saturnParticipator.getUserAttributeList());
		this.saturnMultiWork = this.saturnHumanNode.getSaturnMultiWork();
	}
	
	protected Control createContents(Composite parent) {
		Control contents = super.createContents(parent);
		setMessage(SelectionCandidate.SETTING_ATTRIBUTE + saturnHumanNode.getName()); 
		return contents;
	}
	
	@Override
	protected Control createDialogArea(Composite parent) {

		getShell().setText(SelectionCandidate.ATTRIBUTE_SETTING);
		setTitleImage(Activator.getImage(Images.SATURN_ICONS_MAXNAME)); 
		Composite area = (Composite) super.createDialogArea(parent);

		TabFolder tabFolder;
		tabFolder = new TabFolder(area, SWT.NONE);
		tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
		
		// 汽泡提示框
		final ToolTip tip = new ToolTip(getShell(), SWT.BALLOON | SWT.ICON_WARNING |SWT.ARROW);
		tip.setMessage(Messages.getString("InputNumber"));   //$NON-NLS-1$
		tip.setVisible(false);

		// 基本信息选项卡
		final TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
		tabItem.setText(Messages.getString("BaseInformation"));   //$NON-NLS-1$

		final Group group = new Group(tabFolder, SWT.NONE);
		group.setText(Messages.getString("BaseInformationDefine"));   //$NON-NLS-1$
		tabItem.setControl(group);
		final GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 2;
		group.setLayout(gridLayout);
		
		activityIdLabel = new Label(group, SWT.NONE);
		activityIdLabel.setText(Messages.getString("ActionID"));   //$NON-NLS-1$
		
		activityIdText = new Text(group, SWT.BORDER | SWT.READ_ONLY);
		activityIdText.setTextLimit(50);
		activityIdText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		activityNameLabel = new Label(group, SWT.NONE);
		activityNameLabel.setText(Messages.getString("ActionName"));   //$NON-NLS-1$

		activityNameText = new Text(group, SWT.BORDER);
		activityNameText.setTextLimit(50);
		activityNameText.setFocus();
		activityNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		timeLimitLabel = new Label(group, SWT.NONE);
		timeLimitLabel.setText(Messages.getString("TimeLimited"));   //$NON-NLS-1$

		timeLimitText = new Text(group, SWT.BORDER);
		timeLimitText.setTextLimit(50);
		timeLimitText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

		polymeModeLabel = new Label(group, SWT.NONE);
		polymeModeLabel.setText(Messages.getString("SaturnHumanActivityDialog.6"));   //$NON-NLS-1$

		polymeModeCombo = new Combo(group, SWT.READ_ONLY);
		polymeModeCombo.setLayoutData(new GridData(80, SWT.DEFAULT));
		polymeModeCombo.setItems(SelectionCandidate.polymeModeCandidate);

		descriptionLabel = new Label(group, SWT.NONE);
		descriptionLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
		descriptionLabel.setText(Messages.getString("Description"));   //$NON-NLS-1$

		descriptionText = new Text(group, SWT.V_SCROLL | SWT.BORDER | SWT.WRAP);
		descriptionText.setTextLimit(200);
		final GridData gd_descriptionText = new GridData(SWT.FILL, SWT.FILL, true, true);
		gd_descriptionText.heightHint = 70;
		descriptionText.setLayoutData(gd_descriptionText);

		// logicKey表单信息选项卡
		final TabItem tabItem_1 = new TabItem(tabFolder, SWT.NONE);
		tabItem_1.setText(Messages.getString("EXtendedAction"));   //$NON-NLS-1$
		
		Composite compositeLogicKey = new Composite(tabFolder, SWT.NONE);
		final GridLayout gridLayoutLogicKey = new GridLayout();
		compositeLogicKey.setLayout(gridLayoutLogicKey);
		tabItem_1.setControl(compositeLogicKey);

		final Group group_1 = new Group(compositeLogicKey, SWT.NONE);
		group_1.setText(Messages.getString("FirstEven"));   //$NON-NLS-1$
		final GridData gd_group_1 = new GridData(SWT.FILL, SWT.FILL, true, true);
		gd_group_1.heightHint = 220;
		group_1.setLayoutData(gd_group_1);
		group_1.setLayout(new FormLayout());

		tableViewer = new TableViewer(group_1, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
		table = tableViewer.getTable();
		final FormData fd_table = new FormData();
		fd_table.bottom = new FormAttachment(100, -8);
		fd_table.right = new FormAttachment(100, -100);
		fd_table.top = new FormAttachment(0, 10);
		fd_table.left = new FormAttachment(0, 5);
		table.setLayoutData(fd_table);
		table.setLinesVisible(true);
		table.setHeaderVisible(true);
		tableViewer.setContentProvider(new TableViewerContentProvider());
		tableViewer.setLabelProvider(new LogicKeyAttributeLabelProvider());

		final TableColumn newColumnTableColumn = new TableColumn(table,	SWT.NONE);
		newColumnTableColumn.setWidth(390);
		newColumnTableColumn.setText(Messages.getString("expression"));   //$NON-NLS-1$

		insertButton = new Button(group_1, SWT.NONE);
		insertButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent selectionevent) {
				openAddDialog();
			}
		});
		final FormData fd_addbutton = new FormData();
		fd_addbutton.bottom = new FormAttachment(table, 23, SWT.TOP);
		fd_addbutton.top = new FormAttachment(table, 0, SWT.TOP);
		fd_addbutton.right = new FormAttachment(100, -20);
		fd_addbutton.left = new FormAttachment(100, -75);
		insertButton.setLayoutData(fd_addbutton);
		insertButton.setText(SelectionCandidate.INSERT_BUTTON);

		deleteButton = new Button(group_1, SWT.NONE);
		deleteButton.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked")
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
				logicKeyAttribute = (LogicKeyAttribute) selection.getFirstElement();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_DELETE_RECORD);
				} else {
					List<SaturnAttribute> logicKeyListForDelete = (List<SaturnAttribute>) tableViewer.getInput();
					logicKeyListForDelete.remove(logicKeyAttribute);
					tableViewer.setInput(logicKeyListForDelete);
				}
			}
		});
		final FormData fd_deletebutton = new FormData();
		fd_deletebutton.top = new FormAttachment(insertButton, 5, SWT.BOTTOM);
		fd_deletebutton.right = new FormAttachment(insertButton, 0, SWT.RIGHT);
		fd_deletebutton.left = new FormAttachment(100, -75);
		deleteButton.setLayoutData(fd_deletebutton);
		deleteButton.setText(SelectionCandidate.DELETE_BUTTON); 

		upbutton = new Button(group_1, SWT.NONE);
		upbutton.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked")
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_A_RECORD);
				} else {
					Table table_up = tableViewer.getTable();
					if (tableViewer.getTable() != null) {
						int i = table_up.getSelectionIndex();
						if (i > 0) {
							SaturnAttribute lka = logicKeyTemp.get(i);
							List<SaturnAttribute> logicKeyListForUp = (List<SaturnAttribute>) tableViewer.getInput();
							logicKeyListForUp.remove(lka);
							tableViewer.remove(lka);
							logicKeyListForUp.add(i - 1, lka);
							tableViewer.setInput(logicKeyListForUp);
							table_up.setSelection(i - 1);
						}
					}
				}
			}
		});
		final FormData fd_upbutton = new FormData();
		fd_upbutton.top = new FormAttachment(deleteButton, 5, SWT.BOTTOM);
		fd_upbutton.right = new FormAttachment(deleteButton, 0, SWT.RIGHT);
		fd_upbutton.left = new FormAttachment(100, -75);
		upbutton.setLayoutData(fd_upbutton);
		upbutton.setText(SelectionCandidate.UP_BUTTON); 

		downbutton = new Button(group_1, SWT.NONE);
		downbutton.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked")
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_A_RECORD);  
				} else {
					Table table_down = tableViewer.getTable();
					if (tableViewer.getTable() != null) {
						int i = table_down.getSelectionIndex();
						if (i < tableViewer.getTable().getItemCount() - 1) {
							SaturnAttribute lka = logicKeyTemp.get(i);
							List<SaturnAttribute> logicKeyListForDown = (List<SaturnAttribute>) tableViewer.getInput();
							logicKeyListForDown.remove(lka);
							tableViewer.remove(lka);
							logicKeyListForDown.add(i + 1, lka);
							tableViewer.setInput(logicKeyListForDown);
							table_down.setSelection(i + 1);
						}
					}
				}
			}
		});
		final FormData fd_downbutton = new FormData();
		fd_downbutton.top = new FormAttachment(upbutton, 5, SWT.BOTTOM);
		fd_downbutton.right = new FormAttachment(upbutton, 0, SWT.RIGHT);
		fd_downbutton.left = new FormAttachment(100, -75);
		downbutton.setLayoutData(fd_downbutton);
		downbutton.setText(SelectionCandidate.DOWN_BUTTON); 

		editButton = new Button(group_1, SWT.NONE);
		editButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_EDIT_RECORD);  
				} else {
					logicKeyAttribute = (LogicKeyAttribute) selection.getFirstElement();
					openEditDialog(logicKeyAttribute);
					tableViewer.refresh();
				}
			}
		});
		final FormData fd_editbutton = new FormData();
		fd_editbutton.top = new FormAttachment(downbutton, 5, SWT.BOTTOM);
		fd_editbutton.right = new FormAttachment(downbutton, 0, SWT.RIGHT);
		fd_editbutton.left = new FormAttachment(100, -75);
		editButton.setLayoutData(fd_editbutton);
		editButton.setText(SelectionCandidate.EDIT_BUTTON);
		
		final Group group_1add = new Group(compositeLogicKey, SWT.NONE);
		final GridData gd_group_1add = new GridData(SWT.FILL, SWT.FILL, true, true);
		gd_group_1add.heightHint = 40;
		group_1add.setLayoutData(gd_group_1add);
		group_1add.setText(Messages.getString("LastEvent"));  //$NON-NLS-1$
		final GridLayout gridLayout1add = new GridLayout();
		gridLayout1add.numColumns = 2;
		group_1add.setLayout(gridLayout1add);

		afterRequireText = new Text(group_1add, SWT.BORDER);
		final GridData gd_afterRequireText = new GridData(SWT.FILL, SWT.CENTER, true, false);
		gd_afterRequireText.verticalIndent = 10;
		gd_afterRequireText.heightHint = 15;
		gd_afterRequireText.horizontalIndent = 10;
		gd_afterRequireText.widthHint = 10;
		afterRequireText.setLayoutData(gd_afterRequireText);

		imageLabel = new Label(group_1add, SWT.NONE);
		imageLabel.addMouseListener(new MouseAdapter() {
			public void mouseDown(final MouseEvent e) {
				String  suffixes [] = {"action","jsp"};
				TwoCompontentSearchDialog searchDialog = new TwoCompontentSearchDialog(
						Display.getDefault().getShells()[0],suffixes);
				
				if (searchDialog.open() == Window.OK) {
					SearchResult result = (SearchResult) searchDialog.getFirstResult();
					String tempFilePath = result.getFile() + "";
					String newTempPtah = tempFilePath.replace(result.getSrcName() + "","");
					
					if (result.getFileName().endsWith(".action")) {
						afterRequireText.setText("/"
								+ (result.getProject().getName() + "::")
								+ newTempPtah.replace("\\", "/"));
					} else{
						afterRequireText.setText("/"
								+ result.getProject().getName()
								+ newTempPtah.replace("\\", "/"));
					}
				}
				
			}
		});
		imageLabel.addMouseTrackListener(new MouseTrackAdapter() {
			public void mouseEnter(final MouseEvent e) {
				imageLabel.setImage(Activator.getImage(Images.AMPLIFY_MINUS));
			}
			public void mouseExit(final MouseEvent e) {
				imageLabel.setImage(Activator.getImage(Images.AMPLIFY_PLUS));
			}
		});
		final GridData gd_imageLabel = new GridData();
		gd_imageLabel.verticalIndent = 10;
		imageLabel.setLayoutData(gd_imageLabel);
		imageLabel.setImage(Activator.getImage(Images.AMPLIFY_PLUS));
		
		// formData表单信息选项卡
		final TabItem tabItem_2 = new TabItem(tabFolder, SWT.NONE);
		tabItem_2.setText(Messages.getString("FromInformation"));   //$NON-NLS-1$

		final Group group_2 = new Group(tabFolder, SWT.NONE);
		group_2.setText(Messages.getString("FromInformationDefine"));   //$NON-NLS-1$
		tabItem_2.setControl(group_2);
		final GridLayout gridLayout_2 = new GridLayout();
		group_2.setLayout(gridLayout_2);

		Composite composite2 = new Composite(group_2, SWT.NONE);
		final GridData gd_composite2 = new GridData(SWT.FILL, SWT.FILL, true, true);
		composite2.setLayoutData(gd_composite2);
		composite2.setLayout(new FormLayout());

		tableViewer_2 = new TableViewer(composite2, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
		tableViewer_2.addDoubleClickListener(new IDoubleClickListener() {
			public void doubleClick(final DoubleClickEvent arg0) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_2.getSelection();
				SaturnAttribute attribute = (SaturnAttribute) selection.getFirstElement();
				openFormDataDialogFromDoubleClick(attribute);
			}
		});
		table_2 = tableViewer_2.getTable();
		final FormData fd_table_2 = new FormData();
		fd_table_2.bottom = new FormAttachment(100, -60);
		fd_table_2.right = new FormAttachment(100, -100);
		fd_table_2.top = new FormAttachment(0, 10);
		fd_table_2.left = new FormAttachment(0, 5);
		table_2.setLayoutData(fd_table_2);
		table_2.setLinesVisible(true);
		table_2.setHeaderVisible(true);
		tableViewer_2.setContentProvider(new TableViewerContentProvider());
		tableViewer_2.setLabelProvider(new FormDataAttributeLabelProvider());
		
		tableViewer_2.setColumnProperties(new String[] { "id", "key", "name",
				"type", "accessType", "required" });
		cellEditor = new CellEditor[6];
		cellEditor[0] = null;
		cellEditor[1] = new TextCellEditor(tableViewer_2.getTable());
		cellEditor[2] = new TextCellEditor(tableViewer_2.getTable());
		cellEditor[3] = new ComboBoxCellEditor(tableViewer_2.getTable(),
				SelectionCandidate.formDataTypes, SWT.READ_ONLY);
		cellEditor[4] = new ComboBoxCellEditor(tableViewer_2.getTable(),
				SelectionCandidate.formDataReadWrite, SWT.READ_ONLY);
		cellEditor[5] = new ComboBoxCellEditor(tableViewer_2.getTable(),
				SelectionCandidate.formDataRequired, SWT.READ_ONLY);

		tableViewer_2.setCellEditors(cellEditor);
		tableViewer_2.setCellModifier(new MyCellModifierFormDataAttribute(tableViewer_2));

		final TableColumn newColumnTableColumn_id = new TableColumn(table_2, SWT.NONE);
		newColumnTableColumn_id.setWidth(80);
		newColumnTableColumn_id.setText("ID");

		final TableColumn newColumnTableColumn_0 = new TableColumn(table_2,	SWT.NONE);
		newColumnTableColumn_0.setWidth(80);
		newColumnTableColumn_0.setText(Messages.getString("expresstion"));   //$NON-NLS-1$

		final TableColumn newColumnTableColumn_1 = new TableColumn(table_2, SWT.NONE);
		newColumnTableColumn_1.setWidth(80);
		newColumnTableColumn_1.setText(Messages.getString("Name"));   //$NON-NLS-1$

		final TableColumn newColumnTableColumn_2 = new TableColumn(table_2, SWT.NONE);
		newColumnTableColumn_2.setWidth(80);
		newColumnTableColumn_2.setText(Messages.getString("Type"));   //$NON-NLS-1$

		final TableColumn newColumnTableColumn_3 = new TableColumn(table_2, SWT.NONE);
		newColumnTableColumn_3.setWidth(80);
		newColumnTableColumn_3.setText(Messages.getString("ReadType"));   //$NON-NLS-1$

		final TableColumn newColumnTableColumn_4 = new TableColumn(table_2, SWT.NONE);
		newColumnTableColumn_4.setWidth(80);
		newColumnTableColumn_4.setText(Messages.getString("IsNeed"));   //$NON-NLS-1$

		insertButton_2 = new Button(composite2, SWT.NONE);
		insertButton_2.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				openFormDataDialog();
			}
		});
		final FormData fd_addbutton_2 = new FormData();
		fd_addbutton_2.bottom = new FormAttachment(table_2, 23, SWT.TOP);
		fd_addbutton_2.top = new FormAttachment(table_2, 0, SWT.TOP);
		fd_addbutton_2.right = new FormAttachment(100, -20);
		fd_addbutton_2.left = new FormAttachment(100, -75);
		insertButton_2.setLayoutData(fd_addbutton_2);
		insertButton_2.setText(SelectionCandidate.INSERT_BUTTON); 

		deleteButton_2 = new Button(composite2, SWT.NONE);
		deleteButton_2.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked")
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_2.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_DELETE_RECORD);  
				} else {
					SaturnAttribute fdAttribute = (SaturnAttribute) selection.getFirstElement();
					formDataTemp.remove(fdAttribute);
					orderFormData(formDataTemp);
					tableViewer_2.setInput(formDataTemp);
				}
			}
		});
		final FormData fd_deletebutton_2 = new FormData();
		fd_deletebutton_2.top = new FormAttachment(insertButton_2, 5, SWT.BOTTOM);
		fd_deletebutton_2.right = new FormAttachment(insertButton_2, 0, SWT.RIGHT);
		fd_deletebutton_2.left = new FormAttachment(100, -75);
		deleteButton_2.setLayoutData(fd_deletebutton_2);
		deleteButton_2.setText(SelectionCandidate.DELETE_BUTTON); 

		upbutton_2 = new Button(composite2, SWT.NONE);
		upbutton_2.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked")
			public void widgetSelected(final SelectionEvent selectionevent) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_2.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_A_RECORD);  
				} else {
					SaturnAttribute fdAttribute = (SaturnAttribute) selection.getFirstElement();
					Table table = tableViewer_2.getTable();
					if (tableViewer_2.getTable() != null) {
						int i = table.getSelectionIndex();
						if (i > 0) {
							formDataTemp.remove(fdAttribute);
							formDataTemp.add(i - 1, fdAttribute);
							orderFormData(formDataTemp);
							tableViewer_2.setInput(formDataTemp);
							table.setSelection(i - 1);
						}
					}
				}
			}
		});
		final FormData fd_upbutton_2 = new FormData();
		fd_upbutton_2.top = new FormAttachment(deleteButton_2, 5, SWT.BOTTOM);
		fd_upbutton_2.right = new FormAttachment(deleteButton_2, 0, SWT.RIGHT);
		fd_upbutton_2.left = new FormAttachment(100, -75);
		upbutton_2.setLayoutData(fd_upbutton_2);
		upbutton_2.setText(SelectionCandidate.UP_BUTTON); 

		downbutton_2 = new Button(composite2, SWT.NONE);
		downbutton_2.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked")
			public void widgetSelected(final SelectionEvent selectionevent) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_2.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_A_RECORD);  
				} else {
					SaturnAttribute fdAttribute = (SaturnAttribute) selection.getFirstElement();
					Table table = tableViewer_2.getTable();
					int i = table.getSelectionIndex();
					if (i < tableViewer_2.getTable().getItemCount() - 1) {
						formDataTemp.remove(fdAttribute);
						formDataTemp.add(i + 1, fdAttribute);
						orderFormData(formDataTemp);
						tableViewer_2.setInput(formDataTemp);
						table.setSelection(i + 1);
					}
				}
			}
		});
		final FormData fd_downbutton_2 = new FormData();
		fd_downbutton_2.top = new FormAttachment(upbutton_2, 5, SWT.BOTTOM);
		fd_downbutton_2.right = new FormAttachment(upbutton_2, 0, SWT.RIGHT);
		fd_downbutton_2.left = new FormAttachment(100, -75);
		downbutton_2.setLayoutData(fd_downbutton_2);
		downbutton_2.setText(SelectionCandidate.DOWN_BUTTON); 

		editButton_2 = new Button(composite2, SWT.NONE);
		editButton_2.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent selectionevent) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_2.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_EDIT_RECORD);  
				} else {
					editFormDataDialog((FormDataAttribute) selection.getFirstElement());
					tableViewer_2.refresh();
				}
			}
		});
		final FormData fd_editbutton_2 = new FormData();
		fd_editbutton_2.top = new FormAttachment(downbutton_2, 5, SWT.BOTTOM);
		fd_editbutton_2.right = new FormAttachment(downbutton_2, 0, SWT.RIGHT);
		fd_editbutton_2.left = new FormAttachment(100, -75);
		editButton_2.setLayoutData(fd_editbutton_2);
		editButton_2.setText(SelectionCandidate.EDIT_BUTTON); 
		
		URLLabel = new Label(composite2, SWT.NONE);
		final FormData fd_URLLabel_1 = new FormData();
		fd_URLLabel_1.top = new FormAttachment(table_2, 25, SWT.BOTTOM);
		fd_URLLabel_1.left = new FormAttachment(0, 5);
		fd_URLLabel_1.right = new FormAttachment(0, 75);
		URLLabel.setLayoutData(fd_URLLabel_1);
		URLLabel.setText(Messages.getString("form"));   //$NON-NLS-1$

		URLText = new Text(composite2, SWT.BORDER);
		final FormData fd_URLText = new FormData();
		fd_URLText.top = new FormAttachment(URLLabel, -5, SWT.TOP);
		fd_URLText.left = new FormAttachment(URLLabel, 0, SWT.RIGHT);
		fd_URLText.right = new FormAttachment(100, -50);
		URLText.setLayoutData(fd_URLText);

		final Label browerLabel = new Label(composite2, SWT.NONE);
		browerLabel.addMouseListener(new MouseAdapter() {
			public void mouseDown(final MouseEvent e) {
				String  suffixes [] = {"action","jsp"};
				TwoCompontentSearchDialog searchDialog = new TwoCompontentSearchDialog(
						Display.getDefault().getShells()[0],suffixes);
				
				if (searchDialog.open() == Window.OK) {
					SearchResult result = (SearchResult) searchDialog.getFirstResult();
					String ss = result.getFile() + "";
					
					URLText.setText(("/" + result.getProject().getName() + "::" + ss.replace(result.getSrcName() + "","")).replace("\\","/" ));
				}
				
			}
		});
		browerLabel.addMouseTrackListener(new MouseTrackAdapter() {
			public void mouseEnter(final MouseEvent e) {
				browerLabel.setImage(Activator.getImage(Images.AMPLIFY_MINUS));
			}
			public void mouseExit(final MouseEvent e) {
				browerLabel.setImage(Activator.getImage(Images.AMPLIFY_PLUS));
			}
		});
		browerLabel.setImage(Activator.getImage(Images.AMPLIFY_PLUS));
		final FormData fd_browerLabel = new FormData();
		fd_browerLabel.top = new FormAttachment(URLText, 0, SWT.TOP);
		fd_browerLabel.left = new FormAttachment(URLText, 10, SWT.RIGHT);
		browerLabel.setLayoutData(fd_browerLabel);

		// users表单信息选项卡
		final TabItem tabItem_3 = new TabItem(tabFolder, SWT.NONE);
		tabItem_3.setText(Messages.getString("Partaker"));   //$NON-NLS-1$

		final Group group_3 = new Group(tabFolder, SWT.NONE);
		group_3.setText(Messages.getString("PartakerDefine"));   //$NON-NLS-1$
		tabItem_3.setControl(group_3);
		final GridLayout gridLayout_3 = new GridLayout();
		group_3.setLayout(gridLayout_3);

		Composite composite3 = new Composite(group_3, SWT.NONE);
		final GridData gd_composite3 = new GridData(SWT.FILL, SWT.FILL, true, true);
		composite3.setLayoutData(gd_composite3);
		composite3.setLayout(new FormLayout());
		
		organizationAndRoleButton = new Button(composite3, SWT.RADIO);
		organizationAndRoleButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if(organizationAndRoleButton.getSelection()==true){
					table_3.setEnabled(true);
					insertButton_3.setEnabled(true);
					deleteButton_3.setEnabled(true);
					upbutton_3.setEnabled(true);
					downbutton_3.setEnabled(true);
					editButton_3.setEnabled(true);
					validateUserLogicLabel.setEnabled(true);
					validateUserLogicText.setEnabled(true);
					
					obtainFromActivityLabel.setEnabled(false);
					obtainFromActivityText.setEnabled(true);
					obtainFromActivityButton.setEnabled(false);
					
					customDefineParticipantText.setEnabled(false);
					customDefineParticipantButton2.setEnabled(false);
					
					errorInformationHint();
				}
			}
		});
		final FormData fd_organizationAndRoleButton = new FormData();
		fd_organizationAndRoleButton.top = new FormAttachment(0, 10);
		fd_organizationAndRoleButton.left = new FormAttachment(0, 5);
		organizationAndRoleButton.setLayoutData(fd_organizationAndRoleButton);
		organizationAndRoleButton.setText(Messages.getString("author"));   //$NON-NLS-1$
		
		tableViewer_3 = new TableViewer(composite3, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
		table_3 = tableViewer_3.getTable();
		final FormData fd_table_3 = new FormData();
		fd_table_3.bottom = new FormAttachment(100, -176);
		fd_table_3.right = new FormAttachment(100, -100);
		fd_table_3.top = new FormAttachment(organizationAndRoleButton, 5, SWT.BOTTOM);
		fd_table_3.left = new FormAttachment(0, 30);
		table_3.setLayoutData(fd_table_3);
		table_3.setLinesVisible(true);
		table_3.setHeaderVisible(true);
		tableViewer_3.setContentProvider(new TableViewerContentProvider());
		tableViewer_3.setLabelProvider(new UsersAttributeLabelProvider());
		
		tableViewer_3.setColumnProperties(new String[] { "id", "name", "type"});
		cellEditor = new CellEditor[3];
		cellEditor[0] = new TextCellEditor(tableViewer_3.getTable());
		cellEditor[1] = new TextCellEditor(tableViewer_3.getTable());
		cellEditor[2] = new ComboBoxCellEditor(tableViewer_3.getTable(),
				SelectionCandidate.userTypes, SWT.READ_ONLY);

		tableViewer_3.setCellEditors(cellEditor);
		tableViewer_3.setCellModifier(new MyCellModifierUsersAttribute(tableViewer_3));

		final TableColumn newColumnTableColumnID = new TableColumn(table_3,	SWT.NONE);
		newColumnTableColumnID.setWidth(80);
		newColumnTableColumnID.setText("ID");  

		final TableColumn newColumnTableColumnName = new TableColumn(table_3,SWT.NONE);
		newColumnTableColumnName.setWidth(80);
		newColumnTableColumnName.setText(Messages.getString("Name2"));   //$NON-NLS-1$

		final TableColumn newColumnTableColumnType = new TableColumn(table_3, SWT.NONE);
		newColumnTableColumnType.setWidth(80);
		newColumnTableColumnType.setText(Messages.getString("SaturnHumanActivityType"));   //$NON-NLS-1$

		insertButton_3 = new Button(composite3, SWT.NONE);
		insertButton_3.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				dbConnection = DBConnectionProvider.getInstance().getConnection(getConnectname());
				if (dbConnection == null) {
					MessageDialog.openInformation(null, SelectionCandidate.ERROR, Messages.getString("SaturnHumanActivityDialog.PleaseChooseDBLink"));     //$NON-NLS-1$
				} else {
					dbConnection.getConnectionAsync(new DBConnectionListener() {
						public void onGetConnection(Connection connection) {
							getShell().getDisplay().asyncExec(new Runnable() {
								public void run() {
										UserAddNew addDialog = new UserAddNew(Display.getDefault().getShells()[0], userTemp ,saturnHumanNode,getConnectname(),dbConnection);
										if(addDialog.open() == IDialogConstants.OK_ID){
										int length = userTemp.toArray().length;
										
										if (length == 1) {
											tableViewer_3.setInput(userTemp);
										} else {
											for(int i = 0; i < length - 1; i++) {
												UsersAttribute usersAttribute = (UsersAttribute) userTemp.get(length - 1);
												UsersAttribute usersAttributetemp = (UsersAttribute) userTemp.get(i);
													if (usersAttribute.getId().equals(usersAttributetemp.getId()) 
															&& usersAttribute.getType().equals(usersAttributetemp.getType())) {
														userTemp.remove(usersAttribute);
														MessageDialog.openInformation(null, SelectionCandidate.HINT, Messages.getString("SaturnHumanActivityDialog.CandidateExist")); //$NON-NLS-1$
													} else {
														tableViewer_3.setInput(userTemp);
													}
											}
										}
									}
								}
							});
						}
					});	
				}
			}
		});
		final FormData fd_addbutton_3 = new FormData();
		fd_addbutton_3.bottom = new FormAttachment(table_3, 23, SWT.TOP);
		fd_addbutton_3.top = new FormAttachment(table_3, 0, SWT.TOP);
		fd_addbutton_3.right = new FormAttachment(100, -15);
		fd_addbutton_3.left = new FormAttachment(100, -75);
		insertButton_3.setLayoutData(fd_addbutton_3);
		insertButton_3.setText(SelectionCandidate.INSERT_BUTTON); 

		deleteButton_3 = new Button(composite3, SWT.NONE);
		deleteButton_3.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked")
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_3.getSelection();
				usersAttribute = (UsersAttribute) selection.getFirstElement();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_DELETE_RECORD);  
				} else {
					List<UsersAttribute> usersAttributeForDelete = (List<UsersAttribute>) tableViewer_3.getInput();
					usersAttributeForDelete.remove(usersAttribute);
					tableViewer_3.remove(usersAttribute);
					tableViewer_3.setInput(userTemp);
				}
			}
		});
		final FormData fd_deletebutton_3 = new FormData();
		fd_deletebutton_3.top = new FormAttachment(insertButton_3, 5, SWT.BOTTOM);
		fd_deletebutton_3.right = new FormAttachment(insertButton_3, 0, SWT.RIGHT);
		fd_deletebutton_3.left = new FormAttachment(100, -75);
		deleteButton_3.setLayoutData(fd_deletebutton_3);
		deleteButton_3.setText(SelectionCandidate.DELETE_BUTTON); 

		upbutton_3 = new Button(composite3, SWT.NONE);
		upbutton_3.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked")
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_3.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_A_RECORD);  
				} else {
					Table table = tableViewer_3.getTable();
					if (tableViewer_3.getTable() != null) {
						int i = table.getSelectionIndex();
						if (i > 0) {
							SaturnAttribute user = userTemp.get(i);
							List<SaturnAttribute> usersListForUp = (List<SaturnAttribute>) tableViewer_3.getInput();
							usersListForUp.remove(user);
							tableViewer_3.remove(user);
							usersListForUp.add(i - 1, user);
							tableViewer_3.setInput(usersListForUp);
							table.setSelection(i - 1);
						}
					}
				}
			}
		});
		final FormData fd_upbutton_3 = new FormData();
		fd_upbutton_3.top = new FormAttachment(deleteButton_3, 5, SWT.BOTTOM);
		fd_upbutton_3.right = new FormAttachment(deleteButton_3, 0, SWT.RIGHT);
		fd_upbutton_3.left = new FormAttachment(100, -75);
		upbutton_3.setLayoutData(fd_upbutton_3);
		upbutton_3.setText(SelectionCandidate.UP_BUTTON); 

		downbutton_3 = new Button(composite3, SWT.NONE);
		downbutton_3.addSelectionListener(new SelectionAdapter() {
			@SuppressWarnings("unchecked")
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_3.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_A_RECORD);  
				} else {
					Table table = tableViewer_3.getTable();
					int i = table.getSelectionIndex();
					if (i < tableViewer_3.getTable().getItemCount() - 1) {
						SaturnAttribute user = userTemp.get(i);
						List<SaturnAttribute> usersListForDown = (List<SaturnAttribute>) tableViewer_3.getInput();
						usersListForDown.remove(user);
						tableViewer_3.remove(user);
						usersListForDown.add(i + 1, user);
						tableViewer_3.setInput(usersListForDown);
						table.setSelection(i + 1);
					}
				}
			}
		});
		final FormData fd_downbutton_3 = new FormData();
		fd_downbutton_3.top = new FormAttachment(upbutton_3, 5, SWT.BOTTOM);
		fd_downbutton_3.right = new FormAttachment(upbutton_3, 0, SWT.RIGHT);
		fd_downbutton_3.left = new FormAttachment(100, -75);
		downbutton_3.setLayoutData(fd_downbutton_3);
		downbutton_3.setText(SelectionCandidate.DOWN_BUTTON); 

		editButton_3 = new Button(composite3, SWT.NONE);
		editButton_3.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer_3.getSelection();
				if (selection.isEmpty()) {
					MessageDialog.openInformation(null, SelectionCandidate.HINT, SelectionCandidate.CHOOSE_EDIT_RECORD);  
				} else {
					editUsersDialog((UsersAttribute) selection.getFirstElement());
					tableViewer_3.refresh();
				}
			}
		});
		final FormData fd_editbutton_3 = new FormData();
		fd_editbutton_3.top = new FormAttachment(downbutton_3, 5, SWT.BOTTOM);
		fd_editbutton_3.right = new FormAttachment(downbutton_3, 0, SWT.RIGHT);
		fd_editbutton_3.left = new FormAttachment(100, -75);
		editButton_3.setLayoutData(fd_editbutton_3);
		editButton_3.setText(SelectionCandidate.EDIT_BUTTON); 
		
		validateUserLogicLabel = new Label(composite3, SWT.NONE);
		final FormData fd_validateUserLogicLabel = new FormData();
		fd_validateUserLogicLabel.top = new FormAttachment(table_3, 10, SWT.BOTTOM);
		fd_validateUserLogicLabel.left = new FormAttachment(table_3, 5, SWT.LEFT);
		validateUserLogicLabel.setLayoutData(fd_validateUserLogicLabel);
		validateUserLogicLabel.setText(Messages.getString("SaturnHumanActivityDialog.playRule"));   //$NON-NLS-1$

		validateUserLogicText = new Text(composite3, SWT.BORDER);
		final FormData fd_validateUserLogicText = new FormData();
		fd_validateUserLogicText.right = new FormAttachment(table_3, 0, SWT.RIGHT);
		fd_validateUserLogicText.top = new FormAttachment(validateUserLogicLabel, -5, SWT.TOP);
		fd_validateUserLogicText.left = new FormAttachment(validateUserLogicLabel, 20, SWT.RIGHT);
		validateUserLogicText.setLayoutData(fd_validateUserLogicText);
		
		Label dbLabel = new Label(composite3, SWT.NONE);
		final FormData dbLabel1 = new FormData();
		dbLabel1.top = new FormAttachment(100, -141);
		dbLabel1.left = new FormAttachment(table_3, 5, SWT.LEFT);
		dbLabel.setLayoutData(dbLabel1);
		dbLabel.setText(Messages.getString("SaturnHumanActivityDialog.ChooseDBLink"));   //$NON-NLS-1$

		final Combo combo = new Combo(composite3, SWT.NONE);
		final FormData fd_combo = new FormData();
		fd_combo.right = new FormAttachment(validateUserLogicText, 0, SWT.RIGHT);
		fd_combo.top = new FormAttachment(dbLabel, 0, SWT.TOP);
		fd_combo.left = new FormAttachment(validateUserLogicText, 0, SWT.LEFT);
		combo.setLayoutData(fd_combo);
		List<String> connnectionnames = DBConnectionProvider.getInstance()
		.getAllDBConnectionNames();
		String[] congnectnamestr = new String[connnectionnames.size()];
		connnectionnames.toArray(congnectnamestr);
		combo.setItems(congnectnamestr);
		combo.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent selectionevent) {
				setConnectname(combo.getText().trim());
				tableViewer_3.setInput(null);
				userTemp.clear();
			}
		});
		
		
		flowStartuperButton = new Button(composite3, SWT.RADIO);
		flowStartuperButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if(flowStartuperButton.getSelection()==true){
					table_3.setEnabled(false);
					insertButton_3.setEnabled(false);
					deleteButton_3.setEnabled(false);
					upbutton_3.setEnabled(false);
					downbutton_3.setEnabled(false);
					editButton_3.setEnabled(false);
					validateUserLogicLabel.setEnabled(false);
					validateUserLogicText.setEnabled(false);
					
					obtainFromActivityLabel.setEnabled(false);
					obtainFromActivityText.setEnabled(false);
					obtainFromActivityButton.setEnabled(false);
					
					customDefineParticipantText.setEnabled(false);
					customDefineParticipantButton2.setEnabled(false);
					
					errorInformationHint();
				}
			}
		});
		final FormData fd_flowStartuperButton = new FormData();
		fd_flowStartuperButton.top = new FormAttachment(table_3, 60, SWT.BOTTOM);
		fd_flowStartuperButton.left = new FormAttachment(organizationAndRoleButton, 0, SWT.LEFT);
		flowStartuperButton.setLayoutData(fd_flowStartuperButton);
		flowStartuperButton.setText(Messages.getString("SaturnHumanActivityDialog.startor"));   //$NON-NLS-1$
		
		flowExecutorButton = new Button(composite3, SWT.RADIO);
		flowExecutorButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if(flowExecutorButton.getSelection()==true){
					table_3.setEnabled(false);
					insertButton_3.setEnabled(false);
					deleteButton_3.setEnabled(false);
					upbutton_3.setEnabled(false);
					downbutton_3.setEnabled(false);
					editButton_3.setEnabled(false);
					validateUserLogicLabel.setEnabled(false);
					validateUserLogicText.setEnabled(false);
					
					customDefineParticipantText.setEnabled(false);
					customDefineParticipantButton2.setEnabled(false);
					
					obtainFromActivityLabel.setEnabled(true);
					obtainFromActivityText.setEnabled(true);
					obtainFromActivityButton.setEnabled(true);
					
					errorInformationHint();
				}
			}
		});
		final FormData fd_flowExecutorButton = new FormData();
		fd_flowExecutorButton.top = new FormAttachment(flowStartuperButton, 8, SWT.BOTTOM);
		fd_flowExecutorButton.left = new FormAttachment(flowStartuperButton, 0, SWT.LEFT);
		flowExecutorButton.setLayoutData(fd_flowExecutorButton);
		flowExecutorButton.setText(Messages.getString("SaturnHumanActivityDialog.partaker"));   //$NON-NLS-1$
		
		obtainFromActivityLabel = new Label(composite3, SWT.NONE);
		final FormData fd_obtainFromActivityLabel = new FormData();
		fd_obtainFromActivityLabel.top = new FormAttachment(flowExecutorButton, 10, SWT.BOTTOM);
		fd_obtainFromActivityLabel.left = new FormAttachment(flowExecutorButton, -30, SWT.RIGHT);
		obtainFromActivityLabel.setLayoutData(fd_obtainFromActivityLabel);
		obtainFromActivityLabel.setText(Messages.getString("SaturnHumanActivityDialog.Activitor"));   //$NON-NLS-1$

		obtainFromActivityText = new Text(composite3, SWT.BORDER | SWT.READ_ONLY);
		final FormData fd_obtainFromActivityText = new FormData();
		fd_obtainFromActivityText.right = new FormAttachment(table_3, 0, SWT.RIGHT);
		fd_obtainFromActivityText.top = new FormAttachment(obtainFromActivityLabel, -5, SWT.TOP);
		fd_obtainFromActivityText.left = new FormAttachment(obtainFromActivityLabel, 20, SWT.RIGHT);
		obtainFromActivityText.setLayoutData(fd_obtainFromActivityText);
		
		obtainFromActivityButton = new Button(composite3, SWT.NONE);
		obtainFromActivityButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				openActivitySelectionDialog();
			}
		});
		final FormData fd_obtainFromActivityButton = new FormData();
		fd_obtainFromActivityButton.right = new FormAttachment(editButton_3, 0, SWT.RIGHT);
		fd_obtainFromActivityButton.bottom = new FormAttachment(obtainFromActivityText, 2, SWT.BOTTOM);
		fd_obtainFromActivityButton.top = new FormAttachment(obtainFromActivityText, -2, SWT.TOP);
		fd_obtainFromActivityButton.left = new FormAttachment(editButton_3, 0, SWT.LEFT);
		obtainFromActivityButton.setLayoutData(fd_obtainFromActivityButton);
		obtainFromActivityButton.setText(Messages.getString("SaturnHumanActivityDialog.Choose"));   //$NON-NLS-1$
		
		customDefineParticipantButton = new Button(composite3, SWT.RADIO);
		customDefineParticipantButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if(customDefineParticipantButton.getSelection()==true){
					table_3.setEnabled(false);
					insertButton_3.setEnabled(false);
					deleteButton_3.setEnabled(false);
					upbutton_3.setEnabled(false);
					downbutton_3.setEnabled(false);
					editButton_3.setEnabled(false);
					validateUserLogicLabel.setEnabled(false);
					validateUserLogicText.setEnabled(false);
					
					obtainFromActivityLabel.setEnabled(false);
					obtainFromActivityText.setEnabled(false);
					obtainFromActivityButton.setEnabled(false);
					
					customDefineParticipantText.setEnabled(true);
					customDefineParticipantButton2.setEnabled(true);
					
					errorInformationHint();
				}
			}
		});
		final FormData fd_customDefineParticipantButton = new FormData();
		fd_customDefineParticipantButton.top = new FormAttachment(obtainFromActivityLabel, 20, SWT.BOTTOM);
		fd_customDefineParticipantButton.left = new FormAttachment(organizationAndRoleButton, 0, SWT.LEFT);
		customDefineParticipantButton.setLayoutData(fd_customDefineParticipantButton);
		customDefineParticipantButton.setText(Messages.getString("SaturnHumanActivityDialog.DefineStart")); //$NON-NLS-1$

		customDefineParticipantText = new Text(composite3, SWT.BORDER);
		final FormData fd_customDefineParticipantText = new FormData();
		fd_customDefineParticipantText.top = new FormAttachment(customDefineParticipantButton, -2, SWT.TOP);
		fd_customDefineParticipantText.left = new FormAttachment(validateUserLogicText, 0, SWT.LEFT);
		fd_customDefineParticipantText.right = new FormAttachment(table_3, 0, SWT.RIGHT);
		customDefineParticipantText.setLayoutData(fd_customDefineParticipantText);

		customDefineParticipantButton2 = new Button(composite3, SWT.NONE);
		customDefineParticipantButton2.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				insertCustomDefinePanticipant();
			}
		});
		final FormData fd_customDefineParticipantButton2 = new FormData();
		fd_customDefineParticipantButton2.top = new FormAttachment(customDefineParticipantText, -2, SWT.TOP);
		fd_customDefineParticipantButton2.bottom = new FormAttachment(customDefineParticipantText, 2, SWT.BOTTOM);		
		fd_customDefineParticipantButton2.left = new FormAttachment(obtainFromActivityButton, 0, SWT.LEFT);
		fd_customDefineParticipantButton2.right = new FormAttachment(obtainFromActivityButton, 0, SWT.RIGHT);
		customDefineParticipantButton2.setLayoutData(fd_customDefineParticipantButton2);
		customDefineParticipantButton2.setText(Messages.getString("SaturnHumanActivityDialog.choose2")); //$NON-NLS-1$
		
		// 多工作项选项卡
		final TabItem tabItem_4 = new TabItem(tabFolder, SWT.NONE);
		tabItem_4.setText(Messages.getString("SaturnHumanActivityDialog.WorkOption"));   //$NON-NLS-1$

		Composite composite4 = new Composite(tabFolder, SWT.NONE);
		tabItem_4.setControl(composite4);
		final GridData gd_composite4 = new GridData(SWT.FILL, SWT.FILL, true, true);
		composite4.setLayoutData(gd_composite4);
		composite4.setLayout(new FormLayout());

		multiWorkButton = new Button(composite4, SWT.CHECK);
		multiWorkButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				// 多工作项未选中时的操作
				if (multiWorkButton.getSelection() == false) {
					finishAllButton.setEnabled(false);
					finishNumberButton.setEnabled(false);
					finishPercentButton.setEnabled(false);
					finishRequiredNumText.setEnabled(false);
					finishRequiredPercentText.setEnabled(false);
					finishRequiredNumLabel.setEnabled(false);
					finishRequiredPercentLabel.setEnabled(false);
					sympolLabel.setEnabled(false);
					isAutoCancelLabel.setEnabled(false);
					isAutoCancelCombo.setEnabled(false);

					errorInformationHint();
				}
				// 多工作项选中时的操作
				if (multiWorkButton.getSelection() == true) {
					finishAllButton.setEnabled(true);
					finishNumberButton.setEnabled(true);
					finishPercentButton.setEnabled(true);
					isAutoCancelLabel.setEnabled(true);
					isAutoCancelCombo.setEnabled(true);

					if (finishNumberButton.getSelection() == true) {
						finishRequiredNumText.setEnabled(true);
						finishRequiredNumLabel.setEnabled(true);

						errorInformationHint();
					}
					if (finishPercentButton.getSelection() == true) {
						finishRequiredPercentText.setEnabled(true);
						finishRequiredPercentLabel.setEnabled(true);
						sympolLabel.setEnabled(true);

						errorInformationHint();
					}
				}
			}
		});
		final FormData fd_multiWorkButton = new FormData();
		fd_multiWorkButton.top = new FormAttachment(0, 10);
		fd_multiWorkButton.left = new FormAttachment(0, 10);
		multiWorkButton.setLayoutData(fd_multiWorkButton);
		multiWorkButton.setText(Messages.getString("SaturnHumanActivityDialog.startWorkSeting"));   //$NON-NLS-1$

		group_4 = new Group(composite4, SWT.NONE);
		group_4.setText(Messages.getString("SaturnHumanActivityDialog.OverRule"));   //$NON-NLS-1$
		final FormData fd_group_4 = new FormData();
		fd_group_4.bottom = new FormAttachment(0, 200);
		fd_group_4.right = new FormAttachment(100, -15);
		fd_group_4.top = new FormAttachment(0, 35);
		fd_group_4.left = new FormAttachment(0, 15);
		group_4.setLayoutData(fd_group_4);
		group_4.setLayout(new FormLayout());

		finishAllButton = new Button(group_4, SWT.RADIO);
		finishAllButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if (finishAllButton.getSelection() == true) {
					finishRequiredNumText.setEnabled(false);
					finishRequiredPercentText.setEnabled(false);
					finishRequiredNumLabel.setEnabled(false);
					finishRequiredPercentLabel.setEnabled(false);
					sympolLabel.setEnabled(false);

					errorInformationHint();
				}
			}
		});
		final FormData fd_finishAllButton = new FormData();
		fd_finishAllButton.top = new FormAttachment(0, 8);
		fd_finishAllButton.left = new FormAttachment(0, 10);
		finishAllButton.setLayoutData(fd_finishAllButton);
		finishAllButton.setText(Messages.getString("SaturnHumanActivityDialog.AllDone"));   //$NON-NLS-1$
		finishAllButton.setEnabled(false);

		finishNumberButton = new Button(group_4, SWT.RADIO);
		finishNumberButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if (finishNumberButton.getSelection() == true) {
					finishRequiredNumText.setEnabled(true);
					finishRequiredNumLabel.setEnabled(true);
					finishRequiredPercentText.setEnabled(false);
					finishRequiredPercentLabel.setEnabled(false);
					sympolLabel.setEnabled(false);

					errorInformationHint();

					finishRequiredNumText.setFocus();
				}
			}
		});
		final FormData fd_finishNumberButton = new FormData();
		fd_finishNumberButton.top = new FormAttachment(finishAllButton, 8, SWT.BOTTOM);
		fd_finishNumberButton.left = new FormAttachment(finishAllButton, 0, SWT.LEFT);
		finishNumberButton.setLayoutData(fd_finishNumberButton);
		finishNumberButton.setText(Messages.getString("SaturnHumanActivityDialog.FinishNumber"));   //$NON-NLS-1$
		finishNumberButton.setEnabled(false);

		finishRequiredNumLabel = new Label(group_4, SWT.NONE);
		final FormData fd_finishNumberNeededLabel = new FormData();
		fd_finishNumberNeededLabel.top = new FormAttachment(finishNumberButton,	8, SWT.BOTTOM);
		fd_finishNumberNeededLabel.left = new FormAttachment(finishNumberButton, -20, SWT.RIGHT);
		finishRequiredNumLabel.setLayoutData(fd_finishNumberNeededLabel);
		finishRequiredNumLabel.setText(Messages.getString("SaturnHumanActivityDialog.NeedNumber"));   //$NON-NLS-1$
		finishRequiredNumLabel.setEnabled(false);

		finishRequiredNumText = new Text(group_4, SWT.RIGHT | SWT.BORDER);
		finishRequiredNumText.setText(saturnMultiWork.getFinishRequiredNum().trim());
		finishRequiredNumText.addVerifyListener(new VerifyListener() {
			public void verifyText(final VerifyEvent e) {
				Pattern pattern = Pattern.compile("[0-9]\\d*"); 
				Matcher matcher = pattern.matcher(e.text);
				if (matcher.matches()) {
					e.doit = true;
				} else if (e.text.length() > 0) {
					e.doit = false;
					tip.setLocation(getShell().getBounds().x + group_4.getBounds().x
							+ finishAllButton.getBounds().x + finishAllButton.getBounds().width -20
							+ finishRequiredNumLabel.getBounds().x + 2*finishRequiredNumLabel.getBounds().width
							, getShell().getBounds().y + group_4.getBounds().y
							+ finishAllButton.getBounds().y + finishAllButton.getBounds().height
							+ finishNumberButton.getBounds().y + finishNumberButton.getBounds().height
							+ finishRequiredNumText.getBounds().y + finishRequiredNumText.getBounds().height);
					tip.setVisible(true);
				} else {
					e.doit = true;
				}
			}
		});
		finishRequiredNumText.addModifyListener(new ModifyListener() {
			public void modifyText(final ModifyEvent arg0) {
				errorInformationHint();
			}
		});
		final FormData fd_finishNumberNeededText = new FormData();
		fd_finishNumberNeededText.width = 80;
		fd_finishNumberNeededText.top = new FormAttachment(finishRequiredNumLabel, -5, SWT.TOP);
		fd_finishNumberNeededText.left = new FormAttachment(finishRequiredNumLabel, 25, SWT.RIGHT);
		finishRequiredNumText.setLayoutData(fd_finishNumberNeededText);
		finishRequiredNumText.setEnabled(false);

		finishPercentButton = new Button(group_4, SWT.RADIO);
		finishPercentButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if (finishPercentButton.getSelection() == true) {
					finishRequiredNumText.setEnabled(false);
					finishRequiredPercentText.setEnabled(true);
					finishRequiredNumLabel.setEnabled(false);
					finishRequiredPercentLabel.setEnabled(true);
					sympolLabel.setEnabled(true);

					errorInformationHint();

					finishRequiredPercentText.setFocus();
				}
			}
		});
		final FormData fd_finishPercentButton = new FormData();
		fd_finishPercentButton.top = new FormAttachment(finishRequiredNumText, 8, SWT.BOTTOM);
		fd_finishPercentButton.left = new FormAttachment(finishNumberButton, 0, SWT.LEFT);
		finishPercentButton.setLayoutData(fd_finishPercentButton);
		finishPercentButton.setText(Messages.getString("Percent"));   //$NON-NLS-1$
		finishPercentButton.setEnabled(false);

		finishRequiredPercentLabel = new Label(group_4, SWT.NONE);
		final FormData fd_finishPercentNeededLabel = new FormData();
		fd_finishPercentNeededLabel.top = new FormAttachment(finishPercentButton, 8, SWT.BOTTOM);
		fd_finishPercentNeededLabel.left = new FormAttachment(finishRequiredNumLabel, 0, SWT.LEFT);
		finishRequiredPercentLabel.setLayoutData(fd_finishPercentNeededLabel);
		finishRequiredPercentLabel.setText(Messages.getString("SaturnHumanActivityDialog.NeedFinishPercent"));   //$NON-NLS-1$
		finishRequiredPercentLabel.setEnabled(false);

		finishRequiredPercentText = new Text(group_4, SWT.RIGHT | SWT.BORDER);
		finishRequiredPercentText.setText(saturnMultiWork.getFinishRequiredPercent().trim());
		finishRequiredPercentText.addVerifyListener(new VerifyListener() {
			public void verifyText(final VerifyEvent e) {
				Pattern pattern = Pattern.compile("[0-9]\\d*"); 
				Matcher matcher = pattern.matcher(e.text);
				if (matcher.matches()) {
					e.doit = true;
				} else if (e.text.length() > 0) {
					e.doit = false;
					tip.setLocation(getShell().getBounds().x + group_4.getBounds().x
							+ finishAllButton.getBounds().x + finishAllButton.getBounds().width -20
							+ finishRequiredNumLabel.getBounds().x + 2*finishRequiredNumLabel.getBounds().width
							, getShell().getBounds().y + group_4.getBounds().y
							+ finishAllButton.getBounds().y + finishAllButton.getBounds().height
							+ finishNumberButton.getBounds().y + finishNumberButton.getBounds().height
							+ finishRequiredNumText.getBounds().y + finishRequiredNumText.getBounds().height
							+ 46);
					tip.setVisible(true);
				} else {
					e.doit = true;
				}
			}
		});
		finishRequiredPercentText.addModifyListener(new ModifyListener() {
			public void modifyText(final ModifyEvent arg0) {
				errorInformationHint();
			}
		});
		final FormData fd_finishPercentNeededText = new FormData();
		fd_finishPercentNeededText.top = new FormAttachment(finishRequiredPercentLabel, -5, SWT.TOP);
		fd_finishPercentNeededText.left = new FormAttachment(finishRequiredNumText, 0, SWT.LEFT);
		fd_finishPercentNeededText.right = new FormAttachment(finishRequiredNumText, 0, SWT.RIGHT);
		finishRequiredPercentText.setLayoutData(fd_finishPercentNeededText);
		finishRequiredPercentText.setEnabled(false);

		sympolLabel = new Label(group_4, SWT.NONE);
		final FormData fd_label = new FormData();
		fd_label.top = new FormAttachment(finishRequiredPercentText, 5, SWT.TOP);
		fd_label.left = new FormAttachment(finishRequiredPercentText, 15, SWT.RIGHT);
		sympolLabel.setLayoutData(fd_label);
		sympolLabel.setText("%"); 
		sympolLabel.setEnabled(false);

		isAutoCancelLabel = new Label(group_4, SWT.NONE);
		final FormData fd_autolabel = new FormData();
		fd_autolabel.top = new FormAttachment(finishRequiredPercentLabel, 15, SWT.BOTTOM);
		fd_autolabel.left = new FormAttachment(finishPercentButton, 0, SWT.LEFT);
		isAutoCancelLabel.setLayoutData(fd_autolabel);
		isAutoCancelLabel.setText(Messages.getString("SaturnHumanActivityDialog.FinishProject"));   //$NON-NLS-1$
		isAutoCancelLabel.setEnabled(false);

		isAutoCancelCombo = new Combo(group_4, SWT.NONE | SWT.READ_ONLY);
		final FormData fd_autoCombo = new FormData();
		fd_autoCombo.width = 75;
		fd_autoCombo.top = new FormAttachment(isAutoCancelLabel, -5, SWT.TOP);
		fd_autoCombo.left = new FormAttachment(finishRequiredPercentText, 0, SWT.LEFT);
		isAutoCancelCombo.setLayoutData(fd_autoCombo);
		isAutoCancelCombo.setItems(SelectionCandidate.isAutoCancelCandidate);
		isAutoCancelCombo.setEnabled(false);

		initial();
		
		/**
		 * 名称不可为空
		 * 
		 * */
		activityNameText.addModifyListener(new ModifyListener(){
			public void modifyText(ModifyEvent e) {
				errorInformationHint();
			}
		});
		
		/**
		 * user表单信息选项卡：从活动中获取不可为空
		 * 
		 * */
		obtainFromActivityText.addModifyListener(new ModifyListener() {
			public void modifyText(final ModifyEvent e) {
				errorInformationHint();
			}
		});

		

		

		/**
		 * 时间必须为数字
		 * 
		 * */
		timeLimitText.addVerifyListener(new VerifyListener() {
			public void verifyText(final VerifyEvent e) {
				Pattern pattern = Pattern.compile("[0-9]\\d*"); 
				Matcher matcher = pattern.matcher(e.text);
				if (matcher.matches()) {
					e.doit = true;
				} else if (e.text.length() > 0) {
					e.doit = false;
					tip.setLocation(getShell().getBounds().x + group.getBounds().x
							+ timeLimitText.getLocation().x
							, getShell().getBounds().y + group.getBounds().y
							+ timeLimitText.getLocation().y + 100);
					tip.setVisible(true);
				} else {
					e.doit = true;
				}
			}
		});
		
		return area;
	}
	
	/**
	 * 取得全部Action和本工程下JSP
	 * 
	 * */	
	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		super.createButtonsForButtonBar(parent);
		getButton(IDialogConstants.OK_ID).setEnabled(true);
	}
	
	@SuppressWarnings("unchecked")
	private void openAddDialog(){
		SaturnVocationalLogicDialogForAdd addDialog = new SaturnVocationalLogicDialogForAdd(Display.getDefault().getShells()[0], logicKeyTemp, saturnHumanNode);
		if (addDialog.open() == IDialogConstants.OK_ID) {
			tableViewer.setInput(logicKeyTemp);
		}
	}
	
	@SuppressWarnings("unchecked")
	private void openEditDialog(LogicKeyAttribute logicKeyAttribute){
		SaturnVocationalLogicDialogForEdit editDialog = new SaturnVocationalLogicDialogForEdit(Display.getDefault().getShells()[0], logicKeyAttribute, saturnHumanNode);
		editDialog.open();
	}
	
	protected Point getInitialSize() {
		return new Point(540, 480);
	}
	
	private void openFormDataDialog() {
		SaturnFormDataDialogForAdd addDialog = new SaturnFormDataDialogForAdd(Display.getDefault().getShells()[0], formDataTemp, saturnHumanNode);
		if (addDialog.open() == IDialogConstants.OK_ID) {
			tableViewer_2.setInput(formDataTemp);
		}
	}
	
	private void editFormDataDialog(FormDataAttribute form) {
		SaturnFormDataDialogForEdit editDialog = new SaturnFormDataDialogForEdit(Display
				.getDefault().getShells()[0], form, saturnHumanNode);
		editDialog.open();
	}
	
	public void openFormDataDialogFromDoubleClick(SaturnAttribute attribute) {
		SaturnFormDataDialogForDoubleClick dialog = new SaturnFormDataDialogForDoubleClick(Display.getDefault().getShells()[0], attribute);
		dialog.open();
		tableViewer_2.refresh();
	}
	
	private void editUsersDialog(UsersAttribute user) {
		UserEditNew editDialog = new UserEditNew(Display.getDefault().getShells()[0], user, saturnHumanNode,getConnectname());
		editDialog.open();
	}
	
	private void openActivitySelectionDialog(){
		ActivitySelectionDialog dialog = new ActivitySelectionDialog(Display.getDefault().getShells()[0], saturnHumanNode);
		if(dialog.open() == IDialogConstants.OK_ID){
			obtainFromActivityText.setText(dialog.getObtainFromActivityText());
		}
	}
	
	// 自定义参与者对话框
	@SuppressWarnings("unchecked")
	private void insertCustomDefinePanticipant() {
		CustomDefineParticipantDialog CDPDialog = new CustomDefineParticipantDialog(
				Display.getDefault().getShells()[0], saturnParticipator.getCustomDefineParticipant(), saturnHumanNode);

		if (CDPDialog.open() == IDialogConstants.OK_ID) {
			customDefineParticipantText.setText(saturnParticipator.getCustomDefineParticipant().getKey());
		}
	}
	
	private void copyLogicKeyList(List<SaturnAttribute> list) {
		List<SaturnAttribute> logicKeyTemps = new ArrayList<SaturnAttribute>();
		for (SaturnAttribute saturn : list) {
			LogicKeyAttribute logic = new LogicKeyAttribute(
					(LogicKeyAttribute) saturn);
			logicKeyTemps.add(logic);
		}
		this.logicKeyTemp = logicKeyTemps;
	}

	private void copyFormDataList(List<SaturnAttribute> list) {
		List<SaturnAttribute> formDataTemps = new ArrayList<SaturnAttribute>();
		for (SaturnAttribute saturn : list) {
			FormDataAttribute formData = new FormDataAttribute(
					(FormDataAttribute) saturn);
			formDataTemps.add(formData);
		}
		this.formDataTemp = formDataTemps;
	}

	private void copyUsersList(List<SaturnAttribute> list) {
		List<SaturnAttribute> usersTemps = new ArrayList<SaturnAttribute>();
		for (SaturnAttribute saturn : list) {
			UsersAttribute usersData = new UsersAttribute(
					(UsersAttribute) saturn);
			usersTemps.add(usersData);
		}
		this.userTemp = usersTemps;
	}

	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText(SelectionCandidate.ATTRIBUTE_SETTING); 
		newShell.setImage(Activator.getImage(Images.SATURN_ICONS_SMALLNAME)); 
	}

	protected int getShellStyle() {
		return SWT.CLOSE | SWT.RESIZE;
	}

	private void orderFormData(List<SaturnAttribute> list) {
		for (int i = 0; i < list.size(); i++) {
			FormDataAttribute form = (FormDataAttribute) list.get(i);
			form.setId("" + (i + 1));
		}
	}
	
	private void errorInformationHint(){
		if ("".equals(activityNameText.getText().trim())) {
			setErrorMessage(Messages.getString("SaturnHumanActivityDialog.NameCannotBeEmpty"));    //$NON-NLS-1$
			getButton(IDialogConstants.OK_ID).setEnabled(false);
		} else if ((flowExecutorButton.getSelection()==true)&&("".equals(obtainFromActivityText.getText().trim()))) {
			setErrorMessage(Messages.getString("SaturnHumanActivityDialog.PalyerNotEmpty"));   //$NON-NLS-1$
			getButton(IDialogConstants.OK_ID).setEnabled(false);
		} else {
			if (multiWorkButton.getSelection() == false){
				recoverySurface();
			} else {
				if (finishAllButton.getSelection() == true){
					recoverySurface();
				}
				if (finishNumberButton.getSelection() == true){
					numberNeeded();
				}
				if (finishPercentButton.getSelection() == true){
					percentNeeded();
				}
			}
		}
	}

	private void numberNeeded() {
		if (finishRequiredNumText.getText().contains("-")
				|| ((finishRequiredNumText.getText().length() > 1) && ("0"
						.equals(finishRequiredNumText.getText().substring(0, 1))))) {
			setErrorMessage(Messages.getString("SaturnHumanActivityDialog.InputNotRight"));   //$NON-NLS-1$
			getButton(IDialogConstants.OK_ID).setEnabled(false);
		} else if ("".equals(finishRequiredNumText.getText().trim())) {
			setErrorMessage(Messages.getString("SaturnHumanActivityDialog.FinishCannotEmpty"));   //$NON-NLS-1$
			getButton(IDialogConstants.OK_ID).setEnabled(false);
		} else {
			recoverySurface();
		}
	}

	private void percentNeeded() {
		if ("".equals(finishRequiredPercentText.getText().trim())) {
			setErrorMessage(Messages.getString("SaturnHumanActivityDialog.InputPercentCannotEmpty"));   //$NON-NLS-1$
			getButton(IDialogConstants.OK_ID).setEnabled(false);
		} else if ((Integer.parseInt(finishRequiredPercentText.getText()) > 100)
				|| ((finishRequiredPercentText.getText().length() > 1) && ("0"
						.equals(finishRequiredPercentText.getText().substring(0, 1))))) {
			setErrorMessage(Messages.getString("SaturnHumanActivityDialog.FinishPercentNotRight"));   //$NON-NLS-1$
			getButton(IDialogConstants.OK_ID).setEnabled(false);
		} else {
			recoverySurface();
		}
	}

	private void recoverySurface() {
		setErrorMessage(null);
		getButton(IDialogConstants.OK_ID).setEnabled(true);
	}
	
	private void initial() {
		// 基本信息选项卡
		activityIdText.setText(saturnHumanNode.getId().trim());
		activityNameText.setText(saturnHumanNode.getName().trim());
		timeLimitText.setText(saturnHumanNode.getTimeLimit().trim());
		descriptionText.setText(saturnHumanNode.getDescription());

		polymeModeCombo.setText(RevertCandidate.revertPolymeMode(saturnHumanNode.getPolymeMode().trim()));
		
		// LogicKey选项卡
		tableViewer.setInput(logicKeyTemp);
		afterRequireText.setText(saturnHumanNode.getAfterRequest());
		
		// FormData选项卡
		URLText.setText(saturnHumanNode.getUrl().trim());
		tableViewer_2.setInput(formDataTemp);
		
		// User选项卡
		tableViewer_3.setInput(userTemp);
		
		setIdRead(saturnParticipator.getUserFrom());
		obtainFromActivityText.setText(getIdRead());
		if("1".equals(saturnParticipator.getObtainFromActivityRadioButton())){
			organizationAndRoleButton.setSelection(true);
			flowStartuperButton.setSelection(false);
			flowExecutorButton.setSelection(false);
			customDefineParticipantButton.setSelection(false);
			
			table_3.setEnabled(true);
			insertButton_3.setEnabled(true);
			deleteButton_3.setEnabled(true);
			upbutton_3.setEnabled(true);
			downbutton_3.setEnabled(true);
			editButton_3.setEnabled(true);
			validateUserLogicLabel.setEnabled(true);
			validateUserLogicText.setEnabled(true);
			
			obtainFromActivityLabel.setEnabled(false);
			obtainFromActivityText.setEnabled(false);
			obtainFromActivityButton.setEnabled(false);
			
			customDefineParticipantText.setEnabled(false);
			customDefineParticipantButton2.setEnabled(false);
		}else if("2".equals(saturnParticipator.getObtainFromActivityRadioButton())){
			organizationAndRoleButton.setSelection(false);
			flowStartuperButton.setSelection(true);
			flowExecutorButton.setSelection(false);
			customDefineParticipantButton.setSelection(false);
			
			table_3.setEnabled(false);
			insertButton_3.setEnabled(false);
			deleteButton_3.setEnabled(false);
			upbutton_3.setEnabled(false);
			downbutton_3.setEnabled(false);
			editButton_3.setEnabled(false);
			validateUserLogicLabel.setEnabled(false);
			validateUserLogicText.setEnabled(false);
			
			obtainFromActivityLabel.setEnabled(false);
			obtainFromActivityText.setText("");
			obtainFromActivityText.setEnabled(false);
			obtainFromActivityButton.setEnabled(false);
			
			customDefineParticipantText.setEnabled(false);
			customDefineParticipantButton2.setEnabled(false);
		}else if("3".equals(saturnParticipator.getObtainFromActivityRadioButton())){
			organizationAndRoleButton.setSelection(false);
			flowStartuperButton.setSelection(false);
			flowExecutorButton.setSelection(true);
			customDefineParticipantButton.setSelection(false);
			
			table_3.setEnabled(false);
			insertButton_3.setEnabled(false);
			deleteButton_3.setEnabled(false);
			upbutton_3.setEnabled(false);
			downbutton_3.setEnabled(false);
			editButton_3.setEnabled(false);
			validateUserLogicLabel.setEnabled(false);
			validateUserLogicText.setEnabled(false);
			
			obtainFromActivityLabel.setEnabled(true);
			obtainFromActivityText.setEnabled(true);
			obtainFromActivityButton.setEnabled(true);
			
			customDefineParticipantText.setEnabled(false);
			customDefineParticipantButton2.setEnabled(false);
		}else if("4".equals(saturnParticipator.getObtainFromActivityRadioButton())){
			organizationAndRoleButton.setSelection(false);
			flowStartuperButton.setSelection(false);
			flowExecutorButton.setSelection(false);
			customDefineParticipantButton.setSelection(true);
			
			table_3.setEnabled(false);
			insertButton_3.setEnabled(false);
			deleteButton_3.setEnabled(false);
			upbutton_3.setEnabled(false);
			downbutton_3.setEnabled(false);
			editButton_3.setEnabled(false);
			validateUserLogicLabel.setEnabled(false);
			validateUserLogicText.setEnabled(false);
			
			obtainFromActivityLabel.setEnabled(false);
			obtainFromActivityText.setEnabled(false);
			obtainFromActivityButton.setEnabled(false);
			
			customDefineParticipantText.setEnabled(true);
			customDefineParticipantButton2.setEnabled(true);
		}
		validateUserLogicText.setText(saturnParticipator.getValidateUserLogic().trim());
		customDefineParticipantText.setText(saturnParticipator.getCustomDefineParticipant().getKey().trim());
		
		// 多工作项初始化
		if ("-1".equals(saturnMultiWork.getIsMultiWorkItem())) {
			multiWorkButton.setSelection(false);
		}
		if ("1".equals(saturnMultiWork.getIsMultiWorkItem())) {
			multiWorkButton.setSelection(true);
		}
		if ("1".equals(saturnMultiWork.getIsFinishAll())) {
			finishAllButton.setSelection(true);
			finishNumberButton.setSelection(false);
			finishPercentButton.setSelection(false);
		}
		if ("2".equals(saturnMultiWork.getIsFinishAll())) {
			finishAllButton.setSelection(false);
			finishNumberButton.setSelection(true);
			finishPercentButton.setSelection(false);
		}
		if ("3".equals(saturnMultiWork.getIsFinishAll())) {
			finishAllButton.setSelection(false);
			finishNumberButton.setSelection(false);
			finishPercentButton.setSelection(true);
		}
		if (multiWorkButton.getSelection() == true) {
			finishAllButton.setEnabled(true);
			finishNumberButton.setEnabled(true);
			finishPercentButton.setEnabled(true);
			isAutoCancelLabel.setEnabled(true);
			isAutoCancelCombo.setEnabled(true);

			if (finishNumberButton.getSelection() == true) {
				finishRequiredNumText.setEnabled(true);
				finishRequiredNumLabel.setEnabled(true);
			}
			if (finishPercentButton.getSelection() == true) {
				finishRequiredPercentText.setEnabled(true);
				finishRequiredPercentLabel.setEnabled(true);
				sympolLabel.setEnabled(true);
			}
		}
		isAutoCancelCombo.setText(RevertCandidate.revertAuto(saturnMultiWork
				.getIsAutoCancel().trim()));
	}

	@Override
	protected void buttonPressed(int buttonId) {
		if (saturnHumanNode == null) {
			return;
		}
		if (buttonId == IDialogConstants.OK_ID) {
			// 基本信息
			saturnHumanNode.setName(activityNameText.getText().trim());
			saturnHumanNode.setTimeLimit(timeLimitText.getText().trim());
			saturnHumanNode.setDescription(descriptionText.getText().trim());
			saturnHumanNode.setPolymeMode(RevertCandidate
					.revertFromFaceToVO(polymeModeCombo.getText().trim()));
			
			// logicKey
			saturnHumanNode.setLogicKeyList(logicKeyTemp);
			saturnHumanNode.setAfterRequest(afterRequireText.getText().trim());
			
			// formData
			saturnHumanNode.setUrl(URLText.getText().trim());
			saturnHumanNode.setFormDataAttributeList(formDataTemp);
			
			// users
			if(organizationAndRoleButton.getSelection() == true){
				saturnParticipator.setObtainFromActivityRadioButton("1");
				saturnParticipator.setUserFrom("");
				saturnParticipator.getCustomDefineParticipant().setKey("");
				saturnParticipator.getCustomDefineParticipant().getAttributes().clear();
				saturnParticipator.setValidateUserLogic(validateUserLogicText.getText().trim());
			}
			if(flowStartuperButton.getSelection() == true){
				saturnParticipator.setObtainFromActivityRadioButton("2");
				getStartNodeId();
				saturnParticipator.setValidateUserLogic("");
				saturnParticipator.getCustomDefineParticipant().setKey("");
				saturnParticipator.getCustomDefineParticipant().getAttributes().clear();
			}
			if(flowExecutorButton.getSelection()== true){
				saturnParticipator.setObtainFromActivityRadioButton("3");
				setIdWrite(obtainFromActivityText.getText().trim());
				saturnParticipator.setUserFrom(getIdWrite());
				saturnParticipator.setValidateUserLogic("");
				saturnParticipator.getCustomDefineParticipant().setKey("");
				saturnParticipator.getCustomDefineParticipant().getAttributes().clear();
			}
			if(customDefineParticipantButton.getSelection() == true){
				saturnParticipator.setObtainFromActivityRadioButton("4");
				saturnParticipator.setUserFrom("");
				saturnParticipator.setValidateUserLogic("");
				saturnParticipator.getCustomDefineParticipant().setKey(customDefineParticipantText.getText().trim());
			}
			saturnParticipator.setUserAttributeList(userTemp);
			
			// 多工作项			
			if (multiWorkButton.getSelection() == false) {
				saturnMultiWork.setIsMultiWorkItem("-1");
				saturnMultiWork.setFinishRequiredNum("-1");
				saturnMultiWork.setFinishRequiredPercent("0");
			}
			if (multiWorkButton.getSelection() == true) {
				saturnMultiWork.setIsMultiWorkItem("1");

				if (finishNumberButton.getSelection() == true) {
					saturnMultiWork.setFinishRequiredNum(finishRequiredNumText.getText().trim());
					saturnMultiWork.setFinishRequiredPercent("0");
				}
				if (finishPercentButton.getSelection() == true) {
					saturnMultiWork.setFinishRequiredPercent(finishRequiredPercentText.getText().trim());
					saturnMultiWork.setFinishRequiredNum("-1");
				}
			}
			if (finishAllButton.getSelection() == true) {
				saturnMultiWork.setIsFinishAll("1");
				saturnMultiWork.setFinishRequiredNum("-1");
				saturnMultiWork.setFinishRequiredPercent("0");
			}
			if (finishNumberButton.getSelection() == true) {
				saturnMultiWork.setIsFinishAll("2");
			}
			if (finishPercentButton.getSelection() == true) {
				saturnMultiWork.setIsFinishAll("3");
			}
			saturnMultiWork.setIsAutoCancel(RevertCandidate
					.revertFromFaceToVO(isAutoCancelCombo.getText().trim()));
		}
		super.buttonPressed(buttonId);
	}
	
	/**
	 * 写入ID的get、set方法
	 * 
	 * */
	public String getIdWrite() {
		return idWrite;
	}

	public void setIdWrite(String idWrite) {
		int i = idWrite.indexOf("[");
		int j = idWrite.indexOf("]");
		idWrite = idWrite.substring(i+1, j);
		this.idWrite = idWrite;
	}

	/**
	 * 载入ID的get、set方法
	 * 
	 * */
	public String getIdRead() {
		return idRead;
	}

	public void setIdRead(String idRead) {
		obtainShapes();
		
		for(Shape shape: shapes){
			if(idRead.equals(shape.getId())){
				idRead = shape.getName() + "[" + shape.getId() + "]";
				this.idRead = idRead;
				return;
			}
		}
		
		this.idRead = "";
	}
	
	/**
	 * 得到白板上的所有模型
	 * 
	 * */
	private List<Shape> obtainShapes(){
		shapes = ((ShapesDiagram)saturnHumanNode.getParent()).getShapes();
		return shapes;
	}
	
	/**
	 * 得到开始节点的id，并将其赋给本节点的userFrom属性
	 * 
	 * */
	private void getStartNodeId(){
		obtainShapes();
		
		for(Shape shape: shapes){
			if(shape instanceof SaturnStartNode){
				saturnParticipator.setUserFrom(shape.getId());
				return;
			} else {
				saturnParticipator.setUserFrom("");
			}
		}
	}
	public String getConnectname() {
		return connectname;
	}
	public void setConnectname(String connectname) {
		this.connectname = connectname;
	}
}
